import { DirectiveBinding } from 'vue';
import { useMenuStore } from '@/store';

function checkPermission(el: HTMLElement, binding: DirectiveBinding) {
  const { value } = binding;
  const menuStore = useMenuStore();
  const permission = menuStore.menuList.find(item => value.includes(item['controller']))
  if (!permission) el.parentNode?.removeChild(el);
}

export default {
  mounted: (el: HTMLElement, binding: DirectiveBinding) => checkPermission(el, binding),
  // updated: (el: HTMLElement, binding: DirectiveBinding) => checkPermission(el, binding),
  // created: (el: HTMLElement, binding: DirectiveBinding) => checkPermission(el, binding),
  // beforeMount: (el: HTMLElement, binding: DirectiveBinding) => checkPermission(el, binding),
};
